# 插入
print('插入' * 10)
x = [1, 2, 3]
print(x)
x = x + [4]
x.append(5)
print(x)
x.insert(3, 'w')
x.extend(['a', 'b'])
print(x * 2)

# 删除
print('删除' * 10)
y = ['a', 'b', 'c', 'd', 'e', 'f']
del y[2]
print(y)
y.pop(0)
print(y)
y.remove('f')
print(y)

# 列表元素访问与计数
print('列表元素访问与计数' * 10)
x = [1, 2, 3, 3, 5, 6, 7, 8, 9, 10]
print(x.count(3), x.count(2))

# 列表排序
print('列表排序' * 10)
x = [1, 2, 4, 5, 6, 34, 22, 55, 22, 11, 24, 56, 78]
x.sort()
print(x)
# 导入random模块并给它起别名r
import random as r

# 使用shuffle函数随机打乱列表x的元素顺序
# shuffle会直接修改原列表x，而不是返回新列表
# r.shuffle(x)
# print(x)
# 反转，将数组反过来
x.reverse()
print('reverse:', x)
# 倒叙排序
x.sort(reverse=True)
print('sort:', x)
sorted( x)
print('sorted:', x)
x.sort()
reversed(x)
print('reversed:', x)

# 打包
print('打包' * 10)
a = [1, 2, 3]
b = ['a', 'b', 'c']
print(list(zip(a, b)))

# 枚举
print('枚举' * 10)
for i, j in enumerate(zip(a, b)):
    print(i, j)
for item in enumerate('abcdef'):
    print(item)
    print(item[0], item[1])

# 遍历列表的三种方式
print('遍历列表的三种方式' * 10)
a = ['a', 'b', 'c', 'd', 'e', 'f']
for i in a:
    print(i)
print('第一种结束')
for i in  range(len(a)):
    print(a[i])
print('第二种结束')
for i, e in enumerate(a):
    print(e)
print('第三种结束')